#!/usr/bin/env python
# -*- coding:utf-8 -*-


'''
@CreateTime: 2020/12/09 9:23
@Author :shouke
'''

import os.path
import importlib

def load_plugin_modules():
    '''递归加载当前目录下的所有模块'''


    head, tail = os.path.split(__file__)
    package_father_path, package = os.path.split(head)

    def load_modules(dir_path):
        nonlocal package_father_path
        if not os.path.isdir(dir_path):
            return
        for name in os.listdir(dir_path):
            full_path = os.path.join(dir_path, name)
            if os.path.isdir(full_path):
                load_modules(full_path)
            elif not name.startswith('__') and name.endswith('.py'):
                temp_path = full_path.replace(package_father_path, '')
                relative_path = temp_path.replace('\\', '/').lstrip('/').replace('/', '.')
                importlib.import_module(relative_path.rstrip('.py'))
    load_modules(head)

# 加载模块，自动触发装饰器，获取相关插件函数相关信息
load_plugin_modules()